#ifndef _STREAM_BUFFER_H_
#define _STREAM_BUFFER_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "types.h"
#include "stdlib.h"

typedef enum{
    D_SEX_FEMALE   = 0,
    D_SEX_MALE     = 1,
}USER_SEX;

typedef struct{
    uint32_t userID;
    uint8_t  sex;
    uint8_t  age;
    uint8_t  height;
}UserInfor_t;

typedef struct{
    uint8_t  scaleType;
    uint8_t  messageFlag;
    uint16_t weight;
    uint32_t PID;
    uint16_t impandance;
}ScaleWeight_t;
#pragma pack(1)
typedef struct{
    uint32_t utc;
    uint32_t userID;
	union {
        struct
        {
            uint8_t messageFlag;
            uint8_t ReseveFlag;
        };
        uint16_t flagAndRes;
    };
    uint16_t weightValue;
    uint16_t BodyFatRate;
    uint16_t BodyWaterRate;
    uint16_t BodyMucleRate;
    uint16_t BodyMucleWT;
    uint16_t BMR;
    uint16_t VFatLevle;
    uint16_t BodyProteinRate;
    uint16_t BodyBoneMucleWT;
    uint8_t BodyAge;
    uint8_t BodyBoneWt;
    uint16_t BMI;
    uint16_t standWeight;
    int16_t WeightContorl;
    int16_t MucleContorl;
    int16_t FatContorl;
    uint16_t FatWeight;
    uint16_t OutFatWeight;
    uint16_t BoneMucleRate;
    uint16_t BodyWaterWT;
    uint16_t BodyProteinWT;
    int16_t BodyFatLeleve;
    int8_t BodyType;
    uint8_t BodyScore;
}UserCompostion_t;
#pragma pack()
//--------------------------------------------
extern UserInfor_t     userInfor;
extern UserCompostion_t userFinishData;
//--------------------------------------------
//--------------------------------------------------
#define WISEDA_MIJIA_HEAD        0xCAACA55A       //常数值
#define WISEDA_MIJIA_HEAD_STRE   0x5AA5ACCA       //大端数据流值

#define WISEDA_MIJIA_VER         0x10             //

typedef enum
{
    WisedaCmd_Unlock = 0x00,
    WisedaCmd_Lock,
    WisedaCmd_Synic,
    WisedaCmd_FinishData = 0x12,
}WisedaCmd;

#pragma pack(1)
typedef struct
{
	uint32_t    Head;
    uint8_t     Ver;
	uint8_t     Length;
    uint8_t     cmd;
	uint8_t     data[128];
}wisedaMijiaData_t;
#pragma pack()

typedef enum
{
    UINT_KG = 0x00,
    UINT_JIN,
    UINT_LB,
    UINT_STLB,
}BleMassageUnit;

typedef enum
{
    DpNumber1 = 0x00,
    DpNumber0,
    DpNumber2,
}BleMassageDpNumber;

typedef	union {
    struct
    {
        unsigned char res0         : 1;    // 
        unsigned char dpNumber     : 2;    // 
        unsigned char weightUnit   : 2;    // 
    }flagBit;
    uint8_t flagByte;
}BleMassageFlag_t;

typedef	union {
    struct
    {
        unsigned char MeasureLocked     : 1;    // 
        unsigned char userInforGeted    : 1;    // 
        unsigned char AckuserInfor      : 1;    // 
        unsigned char FinishDataOK      : 1;    // 
        unsigned char FinishDataSend    : 1;    // 
        unsigned char FinishDataAck     : 1;    // 
    }flagBit;
    uint8_t flagByte;
}WisedaMijiaFlag_t;
//--------------------------------------------------
uint16_t CaculateBodyFat(const UserInfor_t* const userInfor,uint16_t weight,uint16_t impandce);
uint16_t CaculateBodyMuscleWeight(const UserInfor_t* const userInfor,uint16_t weight,uint16_t impandce);
uint16_t CaculateBodyWater(const UserInfor_t* const userInfor,uint16_t weight,uint16_t impandce);
uint16_t CaculateBodyProtenPersent(uint16_t weight,uint16_t MuscleWeight,uint16_t waterPersent);
uint16_t CaculateBodyBoneMucaleWeight(const UserInfor_t* const userInfor,uint16_t weight,uint16_t impandce);
uint16_t CaculateBodyBMR(const UserInfor_t* const userInfor,uint16_t weight,uint16_t impandce);
uint16_t CaculateBodyVFR(const UserInfor_t* const userInfor,uint16_t weight,uint16_t impandce);
uint16_t CaculateBodyBMI(uint16_t weight,uint16_t height);
// uint16_t CaculateBodyCtlWeight(uint16_t weight,uint16_t dreamWeight);
// uint16_t CaculateBodyCtlFat(uint16_t Fatweight,uint16_t dreamWeight,uint8_t sex);
uint16_t CaculateBodyAge(const UserInfor_t* const userInfor,uint16_t weight,uint16_t impandce);
int16_t CaculateBodyCtlWeight(uint16_t weight,uint16_t dreamWeight);
int16_t CaculateBodyCtlFat(uint16_t Fatweight,uint16_t dreamWeight,uint8_t sex);
#ifdef __cplusplus
}
#endif

#endif /* endif */